#include <iostream>
#include <cstring>

using namespace std;

const int N = 100010;

int n, m;
int q[N];
int dist[N];

int bfs(int n) {
    int hh = 0, tt = 0;
    q[0] = n;
    
    memset(dist, -1, sizeof dist);
    dist[n] = 0;
    
    int dx[] = {-1, 1};
    while (hh <= tt) {
        int t = q[hh ++ ];
        
        for (int i = 0; i < 3; ++ i) {
            int a = 0;
            if (i == 2) a = t + t;
            else a = t + dx[i];
            
            if (a < 0 || a > 100000) continue;
            if (dist[a] != -1) continue;
            if (a == m) return dist[t] + 1;
            
            q[ ++ tt] = a;
            dist[a] = dist[t] + 1;
        }
    }
}

int main() {
    cin >> n >> m;
    
    cout << bfs(n) << endl;
    
    return 0;
}